package ru.st.selenium;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.testng.annotations.Test;

import static org.junit.Assert.fail;

public class SocTopNameTextField extends ru.st.selenium.pages.TestBase {
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();

    @Test
    public void testUntitled() throws Exception {
        driver.get(baseUrl + "/ru/");
//

        for (int second = 0;; second++) {
            if (second >= 60) fail("timeout");
            try { if ("Войти через:".equals(driver.findElement(By.cssSelector("span.soc-top-name")).getText())) {
                System.out.println("Текстовый элемент Войти через - ок");
                break;
            }
            } catch (Exception e) {}
            Thread.sleep(1000);

        }
    }

    private boolean isElementPresent(By by) {
        try {
            driver.findElement(by);
            return true;
        } catch (NoSuchElementException e) {
            return false;
        }
    }

    private String closeAlertAndGetItsText() {
        try {
            Alert alert = driver.switchTo().alert();
            String alertText = alert.getText();
            if (acceptNextAlert) {
                alert.accept();
            } else {
                alert.dismiss();
            }
            return alertText;
        } finally {
            acceptNextAlert = true;
        }
    }
}